const { browser } = require('webextension-polyfill-ts');


/** {@link https://codetonics.com/javascript/detect-document-ready/#:~:text=%20Detect%20if%20document%20is%20ready%20in%20pure,JavaScript%20is...%203%20Using%20JavaScript%20Timer%20More%20} */
function document_ready(cb) {
  if (document.readyState !== 'loading')
    cb(event);
  else
    document.addEventListener('DOMContentLoaded', cb);
}

document_ready(async ev => {
  const config = await browser.storage.local.get(['obswebsocket-passwd']);

  const passwd_input = document.querySelector('input#passwd');
  passwd_input.setRangeText(config['obswebsocket-passwd'] ?? '');
  passwd_input.addEventListener('change', async ev => {
    await browser.storage.local.set({
      'obswebsocket-passwd': ev.target.value
    });
  });

});
